<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="比赛结果">
          <j-dict-select-tag v-decorator="['result', validatorRules.result]"
                             :triggerChange="true"
                             placeholder="请选择比赛结果"
                             @change = "changeResult"
                             dictCode='result'/>
          <!--<a-input placeholder="请输入0：胜利，1：失败" v-decorator="['result', {}]" />-->
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          v-if="showreward"
          label="奖励">
          <a-input placeholder="请输入奖励金额" v-decorator="['reward', {}]" @change="getreward" type="number" />
        </a-form-item>
        <!--<a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="matchId">
          <a-input placeholder="请输入matchId" v-decorator="['matchId', {}]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="userId">
          <a-input placeholder="请输入userId" v-decorator="['userId', {}]" />
        </a-form-item>-->

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import { postAction } from '@/api/manage'

  export default {
    name: "UpdateSignUpModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
          result:{rules: [{ required: true, message: '请选择比赛结果!' }]},
        },
        url: {
          add: "/signup/signUp/maintain",
          edit: "/signup/signUp/maintain",
        },
        showreward:false,
        ids:'',
        result:'',
        reward:''

      }
    },
    created () {
    },
    methods: {
      routeReload(){
        this.reloadFlag = false
        let ToggleMultipage = "ToggleMultipage"
        this.$store.dispatch(ToggleMultipage,false)
        this.$nextTick(()=>{
          this.$store.dispatch(ToggleMultipage,true)
          this.reloadFlag = true
        })
      },
      add () {
        this.edit({});
      },
      edit (ids) {
        this.form.resetFields();
        this.visible = true;
        this.ids=ids;
      },

      changeResult(value){
        console.log(value);
        this.result=value;
        if(value == 0){
          this.showreward = true;
        }else{
          this.showreward = false;
        }
      },
      getreward(e){
        console.log(e.target.value);
        this.reward=e.target.value;
      },
      close () {
        this.routeReload();
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        let ids=this.ids;
        let reward=this.reward;
        let result=this.result;
        let that=this;
        if(result==''){
          this.$message.warning("请选择比赛结果");
        }else{
          postAction(that.url.add, {ids:ids,reward:reward,result:result}).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.close();
              that.loadData();
              this.routeReload();
              that.routeReload();
            } else {
              that.$message.warning(res.message);
            }
          });
        }

      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>